//
//  testViewController.swift
//  SwitfTest
//
//  Created by runone02 on 2018/12/27.
//  Copyright © 2018年 liqiyun. All rights reserved.
//

import UIKit


/// 声明代理
protocol SecondVCDelegate {
    ///代理方法
    func changeColor(tempString:NSString)
}



class testViewController: BaseViewController {
    // 代理属性
    var delegate:SecondVCDelegate?
    var backString : String?
    var backModel : UserModel?
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = UIColor.red
        
        self.title = "测试代理"
        let btn = UIButton(type: .custom)
        btn.setTitle("点击回传", for: .normal)
        btn.setTitleColor(UIColor.black, for: .normal)
        btn.backgroundColor = UIColor.white
        btn.addTarget(self, action: #selector(add), for: .touchUpInside)
        view.addSubview(btn)
        btn.mas_makeConstraints { (make) in
            make?.centerY.mas_equalTo()(view)
            make?.centerX.mas_equalTo()(view)
            make?.width.mas_equalTo()(100)
            make?.height.mas_equalTo()(100)
        }
         unowned let weakSelf = self
        UserModel.request(with: "", params: nil, success: { (back) in
            print(back.code)
            print("返回的信息:" + (back.message))
            print(back.data.toJSONString() as Any)
            weakSelf.backString = back.message
            
            let cats = JsonUtil.jsonArrayToModel(back.data.toJSONString() as Any as! String, UserModel.self) as! [UserModel]

                for model:UserModel  in cats {
                    self.backModel = model
                    print(model.real_name)
                }
       
        }, failure: nil)

    }

    @objc func add(){
        ///代理方法
        self.delegate?.changeColor(tempString: self.backModel?.real_name as! NSString)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    


}



